import java.util.Arrays;

public class FileData
{

	private String name;
	private long size;
	private int size_pieces;
	private String key;
	private byte[] buffMap;
	
	public FileData(String name, long size, int size_pieces, String key)
	{
		this.name = name;
		this.size = size;
		this.size_pieces = size_pieces;
		this.key = key;
		
		this.buffMap = new byte[this.buffMapSize()];
		Arrays.fill(this.buffMap, (byte)0x0);
	}

	public String format()
	{
		return name+" "+size+" "+size_pieces+" "+key;
	}
	
	
	public void refreshBuffer(int position)
	{
		this.buffMap[(int)(position/8)] |= (1 << (7-position));
	}
	
	
	public void fillBufferMap()
	{
		Arrays.fill(this.buffMap, (byte)0xff);
	}
	
	
	public byte[] getBufferMap()
	{
		return this.buffMap;
	}
	
	
	public int buffMapSize()
	{
		return (int)(Math.ceil((this.size/this.size_pieces)/8));
	}
	
	
	public String getName()
	{
		return this.name;
	}
	
	
	public int getSizePieces()
	{
		return this.size_pieces;
	}
	
	public long getSize()
	{
		return this.size;
	}
	
	public int getNbPieces()
	{
		return (int)(Math.ceil((this.size/this.size_pieces)));
	}
	
	public int sizeLastPiece()
	{
		return (int)(this.size - (this.size_pieces*(this.getNbPieces()-1)));
	}
	
}
